package com.app.controller;


import com.app.model.CustomerModel;
import com.app.model.ReportClassModel;
import com.app.model.ReportMsgModel;
import com.app.model.UserModel;
import com.app.service.CustomerService;
import com.app.service.ReportClassService;
import com.app.service.ReportMsgService;
import com.app.service.UserService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.TokenUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RestController
@Data
public class ReportMsgController {

    @Autowired
    ReportMsgService reportMsgService;

    @Autowired
    public UserService userService;

    @Autowired
    private CustomerService customerService;

    //查询举报分类
    @PostMapping("/insertReport")
    public Result<Object> insertReport(HttpServletRequest request,
                                       @RequestParam("eid") Integer eid,
                                       @RequestParam("pid") Integer pid,
                                       @RequestParam("content") String content,
                                       @RequestParam("classType") String classType
                                       ){

        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        CustomerModel cus = customerService.getCustomerById(user.getCId());
        ReportMsgModel model = new ReportMsgModel();
        model.setEid(eid);
        model.setPid(pid);
        model.setContent(content);
        model.setCusId(cus.getId());
        model.setCrtTime(CommonHelp.getNowTimestamp().toString());
        reportMsgService.insert(model);
        return Result.success("操作成功");
    }

}